/*
 * > /*
>  * INSANE - Interactive Structural Analysis Environment
>  *
>  * Copyright (C) 2003-2004
>  * Universidade Federal de Minas Gerais
>  * Escola de Engenharia
>  * Departamento de Engenharia de Estruturas
>  *
>  * Author's email :     insane@dees.ufmg.br
>  * Author's Website :   http://www.dees.ufmg.br/insane
>  *
>  * This program is free software; you can redistribute it and/or
>  * modify it under the terms of the GNU General Public License
>  * as published by the Free Software Foundation; either version 2
>  * of the License, or any later version.
>  *
>  * This program is distributed in the hope that it will be useful,
>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>  * GNU General Public License for more details.
>  *
>  * You should have received a copy of the GNU General Public License
>  * along with this program; if not, write to the Free Software
>  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
> 1307, USA.
 *
 */

package br.ufmg.dees.insane.ui.rich.prep.view.command;

import java.awt.Point;
import java.awt.Toolkit;

import javax.swing.JOptionPane;

import br.ufmg.dees.insane.commons.command.Command;
import br.ufmg.dees.insane.commons.view.DrawingArea;
import br.ufmg.dees.insane.commons.view.Interface;
import br.ufmg.dees.insane.ui.rich.prep.view.InterfacePrep;

/**
 * This class ia an implementation of Command interface.
 * Its "execute" method gets the current point of DrawingArea
 * and calls the "select" method of Controller.
 *
 * It does exists to be set as a command of the DrawingArea to do
 * selection on runtime.
 *
 * <br>Example:<br>
 * <pre>
 * SelectCommand selectCmd = new SelectCommandCommand(parent);
 * drawingArea.setClickedCommand(selectCmd);
 *</pre>
 *
 * @author Fonseca, Flavio & Pitangueira, Roque & Penna, Samuel
 * @see    DrawingArea#getViewPoint
 */
public class SelectCommand implements Command {
    
    private InterfacePrep parent;
    
//*****************************************************************************
	
    /**
     * Creates new SelectCommand and gets the
     * DrawingArea from parent.
     *
     * @param   parent The parent JFrame
     * @see    Interface#getDrawing
     */
    public SelectCommand(InterfacePrep parent)
    {
        this.parent = (InterfacePrep)parent;
    }
	
    /**
     * Gets the DrawingArea current view point and calls
     * the "select" method on Controller.
     * Repaints drawing in order to color selection.
     *
     * @see    Interface#getController
     */
    public void execute() {
        try
        {
        	// select points
            Point p = parent.getView().getDrawingArea().getViewPoint();
            this.parent.getView().getController().select(p);
            parent.getView().getDrawingArea().repaint();
        }
        catch (Exception e) {
            Toolkit.getDefaultToolkit().beep();
            System.out.print(e.toString());
            JOptionPane.showMessageDialog(parent, e.toString(), "ERROR Message", JOptionPane.ERROR_MESSAGE);
        }
    }
    
//*****************************************************************************
	
    /**
     * Impossible to undo - not implemented.
     */
    public void undo() {}
    
//*****************************************************************************
	
    /**
     * Impossible to redo - not implemented.
     */
    public void redo() {}
    
//*****************************************************************************
}